package com.maker.generator.entity;

import java.io.Serializable;
import java.util.List;
/**
 * 数据库信息
 * @author rainbow
 *
 */
public class MetaGenDBInfo implements Serializable{

	private static final long serialVersionUID = 1070746456145365657L;
	
	public static final String DBTYPE_ORACLE = "ORACLE";
	public static final String DBTYPE_MYSQL = "MYSQL";
	public static final String DBTYPE_POSTGRESQL = "POSTGRESQL";
	public static final String DBTYPE_SQLSERVER = "SQLSERVER";
	public static final String CFG_KEY_DBTYPE = "db_type";
	
	
	private Long id ;
	/**
	 * 驱动名称
	 */
	private String driverName;
	/**
	 * 数据库类型
	 */
	private String dbType;
	/**
	 * 用户名
	 */
	private String userName;
	/**
	 * 用户密码
	 */
	private String userPassword;
	/**
	 * 服务器IP或名称
	 */
	private String hostName;
	/**
	 * 端口号
	 */
	private String portNum;
	/**
	 * 实例名称
	 */
	private String instanceName;
	/**
	 * 数据库表对象
	 */
	private List<MetaGenTable> genTables;
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public String getDriverName() {
		return driverName;
	}
	public void setDriverName(String driverName) {
		this.driverName = driverName;
	}
	public String getDbType() {
		return dbType;
	}
	public void setDbType(String dbType) {
		this.dbType = dbType;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public String getUserPassword() {
		return userPassword;
	}
	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}
	
	public String getHostName() {
		return hostName;
	}
	public void setHostName(String hostName) {
		this.hostName = hostName;
	}
	public String getPortNum() {
		return portNum;
	}
	public void setPortNum(String portNum) {
		this.portNum = portNum;
	}
	public String getInstanceName() {
		return instanceName;
	}
	public void setInstanceName(String instanceName) {
		this.instanceName = instanceName;
	}
	
	public List<MetaGenTable> getGenTables() {
		return genTables;
	}
	public void setGenTables(List<MetaGenTable> genTables) {
		this.genTables = genTables;
	}
	public String getConnectionUrl(){
		String url ="jdbc:";
		switch(dbType){
			case DBTYPE_ORACLE:
				url += "oracle:thin:@"+this.getHostName()+":"+this.getPortNum()+"/"+this.getInstanceName();
				break;
			case DBTYPE_MYSQL :
				url += "mysql://"+this.getHostName()+":"+this.getPortNum()+"/"+this.getInstanceName();
				break;
			case DBTYPE_POSTGRESQL :
				url += "postgresql://"+this.getHostName()+":"+this.getPortNum()+"/"+this.getInstanceName();
				break;
			case DBTYPE_SQLSERVER :
				url += "sqlserver://"+this.getHostName()+":"+this.getPortNum()+";DatabaseName="+this.getInstanceName();
				break;
			default :
				url += "mysql://"+this.getHostName()+":"+this.getPortNum()+"/"+this.getInstanceName();
				break;
		}
		return url;
	}
	
	
	

}
